﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace TomAndJerryMidnightSnack
{

    class InstructionScreen : GameScreen
    {
        Texture2D instructionTexture1;
        Texture2D instructionTexture2;
        Texture2D instructionTexture3;
        Texture2D instructionTexture4;
        Texture2D instructionTexture5;
        Texture2D instructionTexture6;
        Texture2D instructionTexture7;
        Texture2D instructionTexture8;

        Texture2D NextTexture;
        Texture2D PlayTexture;

        Vector2 NextPosition;
        Vector2 PlayPosition;

        int index;
        /// <summary>
        /// Constructor.
        /// </summary>
        public InstructionScreen()
            : base()
        {
            //sound effect for game
            //AudioManager.PushMusic("LoseTheme",false);
            this.Exiting += new EventHandler(HomeScreen_Exiting);
            index = 1;
        }


        void HomeScreen_Exiting(object sender, EventArgs e)
        {
            //stop music
            //AudioManager.PopMusic();
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;

            instructionTexture1 = content.Load<Texture2D>(@"Instruction\struction1");
            instructionTexture2 = content.Load<Texture2D>(@"Instruction\struction2");
            instructionTexture3 = content.Load<Texture2D>(@"Instruction\struction3");
            instructionTexture4 = content.Load<Texture2D>(@"Instruction\struction4");
            instructionTexture5 = content.Load<Texture2D>(@"Instruction\struction5");
            instructionTexture6 = content.Load<Texture2D>(@"Instruction\struction6");
            instructionTexture7 = content.Load<Texture2D>(@"Instruction\struction7");
            instructionTexture8 = content.Load<Texture2D>(@"Instruction\struction8");

            PlayTexture = content.Load<Texture2D>(@"Buttons\play");
            NextTexture = content.Load<Texture2D>(@"Buttons\nextIns");

            PlayPosition = new Vector2(100, 36);
            NextPosition = new Vector2(100, 600);
        }

        /// <summary>
        /// UnloadContent
        /// </summary>

        public override void UnloadContent()
        {
            base.UnloadContent();
        }

        /// <summary>
        /// Handles user input.
        /// </summary>
        public override void HandleInput()
        {
            if (InputManager.IsButtonClicked(new Rectangle(
                (int)PlayPosition.X - PlayTexture.Height, (int)PlayPosition.Y,
                (int)(PlayTexture.Height),
                (int)(PlayTexture.Width))))
            {
                index = 9;
                GameScreen Play = new PlayScreen();
                ExitScreen();
                ScreenManager.AddScreen(Play);
            }
            else if (InputManager.IsButtonClicked(new Rectangle(
                (int)NextPosition.X - NextTexture.Height, (int)NextPosition.Y,
                (int)(NextTexture.Height),
                (int)(NextTexture.Width))))
            {
                index++;
                if (index > 8)
                {
                    GameScreen Play = new PlayScreen();
                    ExitScreen();
                    ScreenManager.AddScreen(Play);
                }
            }
            base.HandleInput();
        }

        /// <summary>
        /// Updates the menu.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }


        /// <summary>
        /// Draws the menu.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            ScreenManager.GraphicsDevice.SetRenderTarget(ScreenManager.FinalImageTarget);
            ScreenManager.GraphicsDevice.Clear(Color.CornflowerBlue);

            // we will do all of our drawing here
            ScreenManager.GraphicsDevice.SetRenderTarget(null);

            spriteBatch.Begin();
            switch (index)
            {
                case 1:
                    spriteBatch.Draw(instructionTexture1, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                case 2:
                    spriteBatch.Draw(instructionTexture2, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                case 3:
                    spriteBatch.Draw(instructionTexture3, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                case 4:
                    spriteBatch.Draw(instructionTexture4, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                case 5:
                    spriteBatch.Draw(instructionTexture5, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                case 6:
                    spriteBatch.Draw(instructionTexture6, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                case 7:
                    spriteBatch.Draw(instructionTexture7, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                case 8:
                    spriteBatch.Draw(instructionTexture8, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
                    break;
                default:

                    break;
            }
            spriteBatch.Draw(PlayTexture, PlayPosition, null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.Draw(NextTexture, NextPosition, null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.End();
        }
    }
}

